package com.fsoft.core.common.base;

import java.io.File;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fsoft.core.utils.FileManage;
import com.fsoft.core.utils.OgnlUtils;
import com.fsoft.core.utils.RetVo;

/**
 * F-Soft 通用Controller
 * @package com.fsoft.core.common
 * @author Fish
 * @email it.fish2010@foxmail.com
 * @date 2020-02-28
 * @CopyRight © F-Soft
 *
 */
@RequestMapping("/core-common")
@Controller
public class CommonController extends BaseController {

	/***
	 * F-Soft 文件上传
	 * @author it_software(it.fish2010@foxmail.com)
	 * @date 2020-02-29
	 * @param params
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/upload", method = RequestMethod.POST)
	public RetVo commonUpload(@RequestParam Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) throws Exception {
		File workSpace = FileManage.getWorkSpace();
		List<Map<String, String>> ret = this.commonsUploadEx(workSpace, "", request, response);
		if (OgnlUtils.isNotEmpty(ret))
			return RetVo.ok(1, ret.get(0));
		return RetVo.error("上传文件失败");
	}

}
